//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.db;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.*;
import org.jpgolay.gui.fixed.*;
import org.jpgolay.gui.iconBar.IconBar;

public class DbGUI extends JInternalFrame {

    public DbGUI() {
        jContentPane = null;
        basicMenu = null;
        iconBar = null;
        mainPanel = null;
        fieldPanel = null;
        companyListLabelAndComboBox = null;
        nameLabelAndTextField = null;
        dbnameLabelAndTextField = null;
        urlLabelAndTextField = null;
        loginLabelAndTextField = null;
        passwordLabelAndTextField = null;
        adminUrlLabelAndTextField = null;
        adminLoginLabelAndTextField = null;
        adminPasswordLabelAndTextField = null;
        notesLabelAndTextField = null;
        dateLabelAndTextField = null;
        lastUpdateLabelAndTextField = null;
        lastUserLabelAndTextField = null;
        initialize();
    }

    private void initialize() {
        setFrameIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/db.png")));
        setJMenuBar(getBasicMenu());
        setTitle("SOCIETE");
        setSize(330, 450);
        setContentPane(getJContentPane());
    }

    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getIconBar(), "North");
            jContentPane.add(getMainPanel(), "Center");
        }
        return jContentPane;
    }

    private BasicMenu getBasicMenu() {
        if (basicMenu == null) {
            basicMenu = new BasicMenu();
        }
        return basicMenu;
    }

    private IconBar getIconBar() {
        if (iconBar == null) {
            iconBar = new IconBar();
        }
        return iconBar;
    }

    private JPanel getMainPanel() {
        if (mainPanel == null) {
            mainPanel = new JPanel();
            mainPanel.setLayout(new BorderLayout());
            mainPanel.add(getCompanyListLabelAndComboBox(), "North");
            mainPanel.add(getFieldPanel(), "Center");
        }
        return mainPanel;
    }

    private JPanel getFieldPanel() {
        if (fieldPanel == null) {
            FlowLayout flowLayout1 = new FlowLayout();
            fieldPanel = new JPanel();
            fieldPanel.setLayout(flowLayout1);
            flowLayout1.setVgap(2);
            fieldPanel.add(getNameLabelAndTextField(), null);
            fieldPanel.add(getDbnameLabelAndTextField(), null);
            fieldPanel.add(getUrlLabelAndTextField(), null);
            fieldPanel.add(getLoginLabelAndTextField(), null);
            fieldPanel.add(getPasswordLabelAndTextField(), null);
            fieldPanel.add(getAdminUrlLabelAndTextField(), null);
            fieldPanel.add(getAdminLoginLabelAndTextField(), null);
            fieldPanel.add(getAdminPasswordLabelAndTextField(), null);
            fieldPanel.add(getNotesLabelAndTextField(), null);
            fieldPanel.add(getDateLabelAndTextField(), null);
            fieldPanel.add(getLastUpdateLabelAndTextField(), null);
            fieldPanel.add(getLastUserLabelAndTextField(), null);
        }
        return fieldPanel;
    }

    private LabelAndComboBox getCompanyListLabelAndComboBox() {
        if (companyListLabelAndComboBox == null) {
            companyListLabelAndComboBox = new LabelAndComboBox();
            companyListLabelAndComboBox.setLabel("Liste des soci\351t\351s");
            companyListLabelAndComboBox.setToolTipText("S\351l\351ctionner une soci\351t\351 dans la liste");
        }
        return companyListLabelAndComboBox;
    }

    private LabelAndTextField getNameLabelAndTextField() {
        if (nameLabelAndTextField == null) {
            nameLabelAndTextField = new LabelAndTextField();
            nameLabelAndTextField.setLabel("Nom de la soci\351t\351");
        }
        return nameLabelAndTextField;
    }

    private LabelAndTextField getDbnameLabelAndTextField() {
        if (dbnameLabelAndTextField == null) {
            dbnameLabelAndTextField = new LabelAndTextField();
            dbnameLabelAndTextField.setLabel("Nom de la base de donn\351e");
        }
        return dbnameLabelAndTextField;
    }

    private LabelAndTextField getUrlLabelAndTextField() {
        if (urlLabelAndTextField == null) {
            urlLabelAndTextField = new LabelAndTextField();
            urlLabelAndTextField.setLabel("URL");
        }
        return urlLabelAndTextField;
    }

    private LabelAndTextField getLoginLabelAndTextField() {
        if (loginLabelAndTextField == null) {
            loginLabelAndTextField = new LabelAndTextField();
            loginLabelAndTextField.setLabel("Login");
        }
        return loginLabelAndTextField;
    }

    private LabelAndTextField getPasswordLabelAndTextField() {
        if (passwordLabelAndTextField == null) {
            passwordLabelAndTextField = new LabelAndTextField();
            passwordLabelAndTextField.setLabel("Password");
        }
        return passwordLabelAndTextField;
    }

    private LabelAndTextField getAdminUrlLabelAndTextField() {
        if (adminUrlLabelAndTextField == null) {
            adminUrlLabelAndTextField = new LabelAndTextField();
            adminUrlLabelAndTextField.setLabel("Admin URL");
            adminUrlLabelAndTextField.setToolTipText("Les champs Admin sont requis pour la cr\351ation d'une nouvelle soci\351t\351");
        }
        return adminUrlLabelAndTextField;
    }

    private LabelAndTextField getAdminLoginLabelAndTextField() {
        if (adminLoginLabelAndTextField == null) {
            adminLoginLabelAndTextField = new LabelAndTextField();
            adminLoginLabelAndTextField.setLabel("Admin Login");
            adminLoginLabelAndTextField.setToolTipText("Les champs Admin sont requis pour la cr\351ation d'une nouvelle soci\351t\351");
        }
        return adminLoginLabelAndTextField;
    }

    private LabelAndTextField getAdminPasswordLabelAndTextField() {
        if (adminPasswordLabelAndTextField == null) {
            adminPasswordLabelAndTextField = new LabelAndTextField();
            adminPasswordLabelAndTextField.setLabel("Admin Password");
            adminPasswordLabelAndTextField.setToolTipText("Les champs Admin sont requis pour la cr\351ation d'une nouvelle soci\351t\351");
        }
        return adminPasswordLabelAndTextField;
    }

    private LabelAndTextField getNotesLabelAndTextField() {
        if (notesLabelAndTextField == null) {
            notesLabelAndTextField = new LabelAndTextField();
            notesLabelAndTextField.setLabel("Notes");
        }
        return notesLabelAndTextField;
    }

    private LabelAndTextField getDateLabelAndTextField() {
        if (dateLabelAndTextField == null) {
            dateLabelAndTextField = new LabelAndTextField();
            dateLabelAndTextField.setLabel("Date de cr\351ation");
            dateLabelAndTextField.getTextField().setEditable(false);
        }
        return dateLabelAndTextField;
    }

    private LabelAndTextField getLastUpdateLabelAndTextField() {
        if (lastUpdateLabelAndTextField == null) {
            lastUpdateLabelAndTextField = new LabelAndTextField();
            lastUpdateLabelAndTextField.setLabel("Derni\350re modification");
            lastUpdateLabelAndTextField.getTextField().setEditable(false);
        }
        return lastUpdateLabelAndTextField;
    }

    private LabelAndTextField getLastUserLabelAndTextField() {
        if (lastUserLabelAndTextField == null) {
            lastUserLabelAndTextField = new LabelAndTextField();
            lastUserLabelAndTextField.setLabel("Modifi\351 par");
            lastUserLabelAndTextField.getTextField().setEditable(false);
        }
        return lastUserLabelAndTextField;
    }

    public BasicMenu getMenuPanel() {
        return getBasicMenu();
    }

    public IconBar getIconBarPanel() {
        return getIconBar();
    }

    public int getCompanyListValue() {
        return getCompanyListLabelAndComboBox().getSelectedIndex();
    }

    public void setCompanyListValue(int index) {
        getCompanyListLabelAndComboBox().setSelectedIndex(index);
    }

    public void setCompanyListValue(String list[]) {
        getCompanyListLabelAndComboBox().setList(list);
    }

    public JComboBox getCompanyListComboBox() {
        return getCompanyListLabelAndComboBox().getComboBox();
    }

    public String getNameValue() {
        return getNameLabelAndTextField().getVal();
    }

    public String getDbnameValue() {
        return getDbnameLabelAndTextField().getVal();
    }

    public String getUrlValue() {
        return getUrlLabelAndTextField().getVal();
    }

    public String getLoginValue() {
        return getLoginLabelAndTextField().getVal();
    }

    public String getPasswordValue() {
        return getPasswordLabelAndTextField().getVal();
    }

    public String getAdminUrlValue() {
        return getAdminUrlLabelAndTextField().getVal();
    }

    public String getAdminLoginValue() {
        return getAdminLoginLabelAndTextField().getVal();
    }

    public String getAdminPasswordValue() {
        return getAdminPasswordLabelAndTextField().getVal();
    }

    public String getNotesValue() {
        return getNotesLabelAndTextField().getVal();
    }

    public String getDateValue() {
        return getDateLabelAndTextField().getVal();
    }

    public String getLastUpdateValue() {
        return getLastUpdateLabelAndTextField().getVal();
    }

    public String getLastUserValue() {
        return getLastUserLabelAndTextField().getVal();
    }

    public void setNameValue(String txt) {
        getNameLabelAndTextField().setVal(txt);
    }

    public void setDbnameValue(String txt) {
        getDbnameLabelAndTextField().setVal(txt);
    }

    public void setUrlValue(String txt) {
        getUrlLabelAndTextField().setVal(txt);
    }

    public void setLoginValue(String txt) {
        getLoginLabelAndTextField().setVal(txt);
    }

    public void setPasswordValue(String txt) {
        getPasswordLabelAndTextField().setVal(txt);
    }

    public void setAdminUrlValue(String txt) {
        getAdminUrlLabelAndTextField().setVal(txt);
    }

    public void setAdminLoginValue(String txt) {
        getAdminLoginLabelAndTextField().setVal(txt);
    }

    public void setAdminPasswordValue(String txt) {
        getAdminPasswordLabelAndTextField().setVal(txt);
    }

    public void setNotesValue(String txt) {
        getNotesLabelAndTextField().setVal(txt);
    }

    public void setDateValue(String txt) {
        getDateLabelAndTextField().setVal(txt);
    }

    public void setLastUpdateValue(String txt) {
        getLastUpdateLabelAndTextField().setVal(txt);
    }

    public void setLastUserValue(String txt) {
        getLastUserLabelAndTextField().setVal(txt);
    }

    public void cleanField() {
        String txt = "";
        getNameLabelAndTextField().setVal(txt);
        getDbnameLabelAndTextField().setVal(txt);
        getUrlLabelAndTextField().setVal(txt);
        getLoginLabelAndTextField().setVal(txt);
        getPasswordLabelAndTextField().setVal(txt);
        getAdminUrlLabelAndTextField().setVal(txt);
        getAdminLoginLabelAndTextField().setVal(txt);
        getAdminPasswordLabelAndTextField().setVal(txt);
        getNotesLabelAndTextField().setVal(txt);
        getDateLabelAndTextField().setVal(txt);
        getLastUpdateLabelAndTextField().setVal(txt);
        getLastUserLabelAndTextField().setVal(txt);
    }

    public void setEnabledField(boolean b) {
        getNameLabelAndTextField().getTextField().setEditable(b);
        getDbnameLabelAndTextField().getTextField().setEditable(b);
        getUrlLabelAndTextField().getTextField().setEditable(b);
        getLoginLabelAndTextField().getTextField().setEditable(b);
        getPasswordLabelAndTextField().getTextField().setEditable(b);
        getAdminUrlLabelAndTextField().getTextField().setEditable(b);
        getAdminLoginLabelAndTextField().getTextField().setEditable(b);
        getAdminPasswordLabelAndTextField().getTextField().setEditable(b);
        getNotesLabelAndTextField().getTextField().setEditable(b);
    }
    private JPanel jContentPane;
    private BasicMenu basicMenu;
    private IconBar iconBar;
    private JPanel mainPanel;
    private JPanel fieldPanel;
    private LabelAndComboBox companyListLabelAndComboBox;
    private LabelAndTextField nameLabelAndTextField;
    private LabelAndTextField dbnameLabelAndTextField;
    private LabelAndTextField urlLabelAndTextField;
    private LabelAndTextField loginLabelAndTextField;
    private LabelAndTextField passwordLabelAndTextField;
    private LabelAndTextField adminUrlLabelAndTextField;
    private LabelAndTextField adminLoginLabelAndTextField;
    private LabelAndTextField adminPasswordLabelAndTextField;
    private LabelAndTextField notesLabelAndTextField;
    private LabelAndTextField dateLabelAndTextField;
    private LabelAndTextField lastUpdateLabelAndTextField;
    private LabelAndTextField lastUserLabelAndTextField;
}
